﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BoletoElectronicoDesktop.AbmUsuario;
using Common;
using BoletoElectronicoDesktop.AbmRol;
using BoletoElectronicoDesktop.AbmClientes;
using BoletoElectronicoDesktop.CargaCredito;
using BoletoElectronicoDesktop.AbmBeneficiarios;
using BoletoElectronicoDesktop.AbmTarjetas;
using BoletoElectronicoDesktop.Login;
using BoletoElectronicoDesktop.TarjetasPremium;
using BoletoElectronicoDesktop.EfectuarCompra;
using BoletoElectronicoDesktop.TarjetasInactividad;
using BoletoElectronicoDesktop.PagoEmpresas;

namespace BoletoElectronicoDesktop
{
    public partial class FormPrincipal : Form
    {
        private int childFormNumber = 0;

        public FormPrincipal()
        {
            Bootstrap b = new Bootstrap();
            InitializeComponent();
            Bootstrap esta = new Bootstrap();

        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void usuariosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FormUsuarioList frm;
                if (this.MdiChildren.Any(f => f is FormUsuarioList))
                {
                    frm = (FormUsuarioList)this.MdiChildren.First(f => f is FormUsuarioList);
                }
                else
                {
                    frm = new FormUsuarioList(Util.Funcionalidad.UsuarioConsulta);
                    frm.MdiParent = this;
                }

                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void nuevoUsuarioToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FormAbmUsuario frm;
                if (this.MdiChildren.Any(f => f is FormAbmUsuario))
                {
                    frm = (FormAbmUsuario)this.MdiChildren.First(f => f is FormAbmUsuario);
                }
                else
                {
                    frm = new FormAbmUsuario(0, Util.Funcionalidad.UsuarioAlta);
                    frm.Owner = this;
                }
                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        private void rolToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FormAbmRol frm;
                if (this.MdiChildren.Any(f => f is FormAbmRol))
                {
                    frm = (FormAbmRol)this.MdiChildren.First(f => f is FormAbmRol);
                }
                else
                {
                    frm = new FormAbmRol(Util.Funcionalidad.RolConsulta);
                    frm.MdiParent = this;
                }
                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void clienteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FormClientesList frm;
                if (this.MdiChildren.Any(f => f is FormUsuarioList))
                {
                    frm = (FormClientesList)this.MdiChildren.First(f => f is FormUsuarioList);
                }
                else
                {
                    frm = new FormClientesList(Util.Funcionalidad.ClienteConsulta);
                    frm.MdiParent = this;
                }

                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void cargarCrédioToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void beneficiarioToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FormBeneficiariosList frm;
                if (this.MdiChildren.Any(f => f is FormBeneficiariosList))
                {
                    frm = (FormBeneficiariosList)this.MdiChildren.First(f => f is FormBeneficiariosList);
                }
                else
                {
                    frm = new FormBeneficiariosList(Util.Funcionalidad.BeneficiarioConsulta);
                    frm.MdiParent = this;
                }

                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void logInToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FormLogin frm;
                if (this.MdiChildren.Any(f => f is FormLogin))
                {
                    frm = (FormLogin)this.MdiChildren.First(f => f is FormLogin);
                }
                else
                {
                    frm = new FormLogin(Util.Funcionalidad.Login);
                    frm.MdiParent = this;
                }

                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void clientesPremiumToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FormTarjetasPremium frm;
                if (this.MdiChildren.Any(f => f is FormTarjetasPremium))
                {
                    frm = (FormTarjetasPremium)this.MdiChildren.First(f => f is FormTarjetasPremium);
                }
                else
                {
                    frm = new FormTarjetasPremium(Util.Funcionalidad.TarjetasPermiumConsulta);
                    frm.MdiParent = this;
                }

                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void efectuarCompraToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                frmEfectuarCompra frm;
                if (this.MdiChildren.Any(f => f is frmEfectuarCompra))
                {
                    frm = (frmEfectuarCompra)this.MdiChildren.First(f => f is frmEfectuarCompra);
                }
                else
                {
                    frm = new frmEfectuarCompra(Util.Funcionalidad.CompraAlta);
                    frm.MdiParent = this;
                }

                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void administrarTarjetaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FormTarjetasList frm;
                if (this.MdiChildren.Any(f => f is FormTarjetasList))
                {
                    frm = (FormTarjetasList)this.MdiChildren.First(f => f is FormTarjetasList);
                }
                else
                {
                    frm = new FormTarjetasList(Util.Funcionalidad.TarjetaConsulta);
                    frm.MdiParent = this;
                }

                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }



        private void efectuarPagoToolStripMenuItem_Click(object sender, EventArgs e)
        {

            try
            {
                FormPago frm;
                if (this.MdiChildren.Any(f => f is FormPago))
                {
                    frm = (FormPago)this.MdiChildren.First(f => f is FormPago);
                }
                else
                {
                    frm = new FormPago(Util.Funcionalidad.PagoAlta);
                    frm.MdiParent = this;
                }

                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutUs frm;
            if (this.OwnedForms.Any(f => f is AboutUs))
            {
                frm = (AboutUs)this.OwnedForms.First(f => f is AboutUs);
            }
            else
            {
                frm = new AboutUs();
            }

            frm.ShowDialog(this);
        }

        private void cargarCréditoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FormCargaCredito frm;
                if (this.MdiChildren.Any(f => f is FormCargaCredito))
                {
                    frm = (FormCargaCredito)this.MdiChildren.First(f => f is FormCargaCredito);
                }
                else
                {
                    frm = new FormCargaCredito(Util.Funcionalidad.CargaAlta);
                    frm.MdiParent = this;
                }

                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void tarjetasInactivasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                FormTarjetasInactividad frm;
                if (this.MdiChildren.Any(f => f is FormTarjetasInactividad))
                {
                    frm = (FormTarjetasInactividad)this.MdiChildren.First(f => f is FormTarjetasInactividad);
                }
                else
                {
                    frm = new FormTarjetasInactividad(Util.Funcionalidad.TarjetaConsulta);
                    frm.MdiParent = this;
                }

                frm.Show();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

    }
}
